﻿using System ;

namespace OpenLightGroup.Common
{
    public class ActionToken<T>
    : NotifyingObject
    {
        private T _value ;
        private Guid _id ;

        public ActionToken ( T value )
        : this ( Guid.NewGuid ( ), value )
        {
        }

        public ActionToken ( Guid id, T value )
        : base ( )
        {
            this.Id = id ;
            this.Value = value ;
        }

        public ActionToken ( )
        : this ( Guid.Empty, default(T) )
        {
        }

        public Guid Id
        {
            get
            {
                return this._id ;
            }
            set
            {
                if ( this._id != value )
                {
                    this._id = value ;
                    this.RaisePropertyChanged ( "Id" ) ;
                }
            }
        }

        public T Value
        {
            get
            {
                return this._value ;
            }
            set
            {
                if ( this._value == null || !this._value.Equals ( value ) )
                {
                    this._value = value ;
                    this.RaisePropertyChanged ( "Value" ) ;
                }
            }
        }

        public override bool Equals ( object obj )
        {
            var input = obj as ActionToken<T> ;
            var output = false ;
            if ( input != null )
            {
                output = input.Id == this.Id ;
            }
            else
            {
                output = false ;
            }
            return output ;
        }

        public override int GetHashCode ( )
        {
            return this.Id.GetHashCode ( ) ;
        }

        public override string ToString ( )
        {
            return this.Value.ToString ( ) ;
        }
    }

    public class ActionToken
    : ActionToken<string>
    {
    }
}